Leaflet is an open source JavaScript library for ineracticve maps:
rgdal packagelibrary(maps)
package <U+393C><U+3E31>maps<U+393C><U+3E32> was built under R version 3.5.3
m <- leaflet() %>%
setView(lng = 145.0431, lat = -37.8773, zoom = 15) %>%
addTiles()
m
NA
Note: that the use of %>% basically means use the result of the previous function as the first parameter of the next function.
The magrittr package offers a set of operators which make your code more readable by:
Is the equiv of writing:
#call the functionality of leaflet
m <- leaflet()
#set where the map is
m <- setView(m,
lng = 145.0431, lat = -37.8773, zoom = 15)
#Add graphics elements and layers to the map widget
m <- addTiles(m)
m
use help(addProviderTiles) to check other available tiles.
m %>% addProviderTiles("Stamen.TonerLite")
#read some data
data <- read.csv("vet_schools_in_victoria.csv")
head(data)
#dataset is very large so only place the first 30 record
leaflet(data = data[1:30, ] ) %>%
#add the map
addTiles() %>%
#add some markers
addMarkers(~longitude, #x values
~latitude, #y values
#label that pops up when you click
popup= ~as.character(location))
Now plot all the data:
leaflet(data = data) %>%
addTiles() %>%
addMarkers(~longitude, #x values
~latitude, #y values
#label that pops up when you click
popup= ~as.character(location),
#cluster markers when zooming out and in
clusterOptions = markerClusterOptions())
#preprocess that data
data <- read.csv("Household-heating-by-State-2008.csv", header=T)
head(data)
#change the name of column 4 (X..Housing.Units.That.Are.Mobile.Homes) to Mobile homes
names(data)[4]<- "MobileHomes"
ag <- aggregate(MobileHomes~ States, #group by state
FUN = mean, #find the mean number of mobile homes
data = data) #in the data dataset
#make lower case as map data (see below) uses lower case!
ag$States <- tolower(ag$States)
head(ag)
mapStates <- map("state",
fill = TRUE,
plot = FALSE)
#find the related rate for each state
rates <- ag$MobileHomes[match(mapStates$names, ag$States)]
#map the data
cpal <- colorNumeric("Blues", rates) # prepare the color mapping
#create the blak cavas
leaflet(mapStates) %>%
addTiles() %>%
addPolygons(
stroke = FALSE,
smoothFactor = 0.2,
fillOpacity = 1,
#use the rate of each state to find the correct colour
color = ~cpal(rates)
)
Not all the states appear…
#print variables
mapStates$names
[1] "alabama" "arizona" "arkansas"
[4] "california" "colorado" "connecticut"
[7] "delaware" "district of columbia" "florida"
[10] "georgia" "idaho" "illinois"
[13] "indiana" "iowa" "kansas"
[16] "kentucky" "louisiana" "maine"
[19] "maryland" "massachusetts:martha's vineyard" "massachusetts:main"
[22] "massachusetts:nantucket" "michigan:north" "michigan:south"
[25] "minnesota" "mississippi" "missouri"
[28] "montana" "nebraska" "nevada"
[31] "new hampshire" "new jersey" "new mexico"
[34] "new york:manhattan" "new york:main" "new york:staten island"
[37] "new york:long island" "north carolina:knotts" "north carolina:main"
[40] "north carolina:spit" "north dakota" "ohio"
[43] "oklahoma" "oregon" "pennsylvania"
[46] "rhode island" "south carolina" "south dakota"
[49] "tennessee" "texas" "utah"
[52] "vermont" "virginia:chesapeake" "virginia:chincoteague"
[55] "virginia:main" "washington:san juan island" "washington:lopez island"
[58] "washington:orcas island" "washington:whidbey island" "washington:main"
[61] "west virginia" "wisconsin" "wyoming"
ag$States
[1] "#n/a" "alabama" "alaska" "arizona" "arkansas" "california" "colorado"
[8] "connecticut" "delaware" "florida" "georgia" "hawaii" "idaho" "illinois"
[15] "indiana" "iowa" "kansas" "kentucky" "louisiana" "maine" "maryland"
[22] "massachusetts" "michigan" "minnesota" "mississippi" "missouri" "montana" "nebraska"
[29] "nevada" "new hampshire" "new jersey" "new mexico" "new york" "north carolina" "north dakota"
[36] "ohio" "oklahoma" "oregon" "pennsylvania" "rhode island" "south carolina" "south dakota"
[43] "tennessee" "texas" "utah" "vermont" "virginia" "washington" "west virginia"
[50] "wisconsin" "wyoming"
We can see some different spelling: - e.g. “virginia:chesapeake” , “washington:main”, etc…
# split the string with : as seperator
spliteNames <- strsplit(mapStates$names, ":")
# get first part of the origin string;
# e.g. get washington from washington:san juan island
firstPartNames <- lapply(spliteNames, function(x) x[1])
rates <- ag$MobileHomes[match(firstPartNames, ag$States)]
Now try again:
# prepare the color mapping
cpal <- colorNumeric("Blues", rates)
# create a blank canvas
leaflet(mapStates) %>%
# add tile
addTiles() %>%
# draw polygons on top of the base map (tile)
addPolygons(
stroke = FALSE,
smoothFactor = 0.2,
fillOpacity = 1,
color = ~cpal(rates) # use the rate of each state to find the correct color
)
#install.packages(rdgal)
library(rgdal)
package <U+393C><U+3E31>rgdal<U+393C><U+3E32> was built under R version 3.5.3Loading required package: sp
package <U+393C><U+3E31>sp<U+393C><U+3E32> was built under R version 3.5.3rgdal: version: 1.4-3, (SVN revision 828)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
Path to GDAL shared files: C:/Users/pasulj/Documents/R/win-library/3.5/rgdal/gdal
GDAL binary built with GEOS: TRUE
Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
Path to PROJ.4 shared files: C:/Users/pasulj/Documents/R/win-library/3.5/rgdal/proj
Linking to sp version: 1.3-1
#read data
world_map <- readOGR("ne_50m_admin_0_countries.shp")
OGR data source with driver: ESRI Shapefile
Source: "C:\Users\pasulj\OneDrive - Bond University\GDDS\FIT5147\Week 3\Activities\ne_50m_admin_0_countries.shp", layer: "ne_50m_admin_0_countries"
with 241 features
It has 63 fields
head(world_map)
An object of class "SpatialPolygonsDataFrame"
Slot "data":
Slot "polygons":
[[1]]
An object of class "Polygons"
Slot "Polygons":
[[1]]
An object of class "Polygon"
Slot "labpt":
[1] -69.98268 12.52088
Slot "area":
[1] 0.01286311
Slot "hole":
[1] FALSE
Slot "ringDir":
[1] 1
Slot "coords":
[,1] [,2]
[1,] -69.89912 12.45200
[2,] -69.89570 12.42300
[3,] -69.94219 12.43853
[4,] -70.00415 12.50049
[5,] -70.06611 12.54697
[6,] -70.05088 12.59707
[7,] -70.03511 12.61411
[8,] -69.97314 12.56763
[9,] -69.91182 12.48047
[10,] -69.89912 12.45200
Slot "plotOrder":
[1] 1
Slot "labpt":
[1] -69.98268 12.52088
Slot "ID":
[1] "0"
Slot "area":
[1] 0.01286311
[[2]]
An object of class "Polygons"
Slot "Polygons":
[[1]]
An object of class "Polygon"
Slot "labpt":
[1] 66.00473 33.83523
Slot "area":
[1] 62.55793
Slot "hole":
[1] FALSE
Slot "ringDir":
[1] 1
Slot "coords":
[,1] [,2]
[1,] 74.89131 37.23164
[2,] 74.84023 37.22505
[3,] 74.76738 37.24917
[4,] 74.73896 37.28564
[5,] 74.72666 37.29072
[6,] 74.66895 37.26670
[7,] 74.55898 37.23662
[8,] 74.37217 37.15771
[9,] 74.37617 37.13735
[10,] 74.49795 37.05723
[11,] 74.52646 37.03066
[12,] 74.54141 37.02217
[13,] 74.43105 36.98369
[14,] 74.19473 36.89687
[15,] 74.03887 36.82573
[16,] 74.00186 36.82310
[17,] 73.90781 36.85293
[18,] 73.76914 36.88848
[19,] 73.73184 36.88779
[20,] 73.41113 36.88169
[21,] 73.11680 36.86855
[22,] 72.99375 36.85161
[23,] 72.76621 36.83501
[24,] 72.62285 36.82959
[25,] 72.53135 36.80200
[26,] 72.43115 36.76582
[27,] 72.32695 36.74238
[28,] 72.24980 36.73472
[29,] 72.15674 36.70088
[30,] 72.09561 36.63374
[31,] 71.92070 36.53418
[32,] 71.82227 36.48608
[33,] 71.77266 36.43184
[34,] 71.71641 36.42656
[35,] 71.62051 36.43647
[36,] 71.54590 36.37769
[37,] 71.46328 36.29326
[38,] 71.31260 36.17119
[39,] 71.23291 36.12178
[40,] 71.18506 36.04209
[41,] 71.22021 36.00068
[42,] 71.34287 35.93853
[43,] 71.39756 35.88018
[44,] 71.42754 35.83374
[45,] 71.48359 35.71460
[46,] 71.51904 35.59751
[47,] 71.57197 35.54683
[48,] 71.58740 35.46084
[49,] 71.60059 35.40791
[50,] 71.57197 35.37041
[51,] 71.54551 35.32852
[52,] 71.54551 35.28887
[53,] 71.57725 35.24800
[54,] 71.60527 35.21177
[55,] 71.62051 35.18301
[56,] 71.60166 35.15068
[57,] 71.54551 35.10142
[58,] 71.51709 35.05112
[59,] 71.45508 34.96694
[60,] 71.35811 34.90962
[61,] 71.29414 34.86772
[62,] 71.22578 34.77954
[63,] 71.11328 34.68159
[64,] 71.06563 34.59961
[65,] 71.01631 34.55464
[66,] 70.96563 34.53037
[67,] 70.97891 34.48628
[68,] 71.02295 34.43115
[69,] 71.09570 34.36943
[70,] 71.09238 34.27324
[71,] 71.08906 34.20405
[72,] 71.09131 34.12026
[73,] 71.05156 34.04971
[74,] 70.84844 33.98188
[75,] 70.65400 33.95229
[76,] 70.41572 33.95044
[77,] 70.32568 33.96113
[78,] 70.25361 33.97598
[79,] 69.99473 34.05181
[80,] 69.88965 34.00728
[81,] 69.86807 33.89766
[82,] 70.05664 33.71987
[83,] 70.13418 33.62075
[84,] 70.21973 33.45469
[85,] 70.28418 33.36904
[86,] 70.26113 33.28901
[87,] 70.09023 33.19810
[88,] 69.92012 33.11250
[89,] 69.70371 33.09473
[90,] 69.56777 33.06416
[91,] 69.50156 33.02007
[92,] 69.45312 32.83281
[93,] 69.40459 32.76426
[94,] 69.40537 32.68271
[95,] 69.35947 32.59033
[96,] 69.28994 32.53057
[97,] 69.24141 32.43354
[98,] 69.25654 32.24946
[99,] 69.27930 31.93682
[100,] 69.18691 31.83809
[101,] 69.08311 31.73848
[102,] 68.97344 31.66738
[103,] 68.86895 31.63423
[104,] 68.78232 31.64644
[105,] 68.71367 31.70806
[106,] 68.67324 31.75972
[107,] 68.59766 31.80298
[108,] 68.52070 31.79414
[109,] 68.44326 31.75449
[110,] 68.31982 31.76768
[111,] 68.21396 31.80737
[112,] 68.16104 31.80298
[113,] 68.13018 31.76328
[114,] 68.01719 31.67798
[115,] 67.73984 31.54819
[116,] 67.62676 31.53877
[117,] 67.57822 31.50649
[118,] 67.59756 31.45332
[119,] 67.64707 31.40996
[120,] 67.73350 31.37925
[121,] 67.73789 31.34395
[122,] 67.66152 31.31299
[123,] 67.59639 31.27769
[124,] 67.45283 31.23462
[125,] 67.28730 31.21782
[126,] 67.11592 31.24292
[127,] 67.02773 31.30024
[128,] 66.92432 31.30562
[129,] 66.82930 31.26367
[130,] 66.73135 31.19453
[131,] 66.62422 31.04604
[132,] 66.59580 31.01997
[133,] 66.56680 30.99658
[134,] 66.49736 30.96455
[135,] 66.39717 30.91221
[136,] 66.34688 30.80278
[137,] 66.28691 30.60791
[138,] 66.30098 30.50298
[139,] 66.30547 30.32114
[140,] 66.28184 30.19346
[141,] 66.23848 30.10962
[142,] 66.24717 30.04351
[143,] 66.31338 29.96855
[144,] 66.28691 29.92002
[145,] 66.23125 29.86572
[146,] 66.17705 29.83560
[147,] 65.96162 29.77891
[148,] 65.66621 29.70132
[149,] 65.47100 29.65156
[150,] 65.18047 29.57764
[151,] 65.09551 29.55947
[152,] 64.91895 29.55278
[153,] 64.82734 29.56416
[154,] 64.70352 29.56714
[155,] 64.52109 29.56450
[156,] 64.39375 29.54434
[157,] 64.26611 29.50693
[158,] 64.17217 29.46035
[159,] 64.11797 29.41426
[160,] 64.09873 29.39194
[161,] 63.97100 29.43008
[162,] 63.56758 29.49800
[163,] 62.47656 29.40835
[164,] 62.37344 29.42539
[165,] 62.00098 29.53042
[166,] 61.52148 29.66567
[167,] 61.22441 29.74941
[168,] 60.84336 29.85869
[169,] 61.10410 30.12842
[170,] 61.33164 30.36372
[171,] 61.55947 30.59937
[172,] 61.78418 30.83193
[173,] 61.81084 30.91328
[174,] 61.81426 31.07256
[175,] 61.75508 31.28530
[176,] 61.66016 31.38242
[177,] 61.34648 31.42163
[178,] 61.11074 31.45112
[179,] 60.85410 31.48325
[180,] 60.82070 31.49517
[181,] 60.79160 31.66060
[182,] 60.80430 31.73447
[183,] 60.78750 31.87720
[184,] 60.78994 31.98711
[185,] 60.82725 32.16797
[186,] 60.82930 32.24941
[187,] 60.71045 32.60000
[188,] 60.64453 32.79438
[189,] 60.57656 32.99487
[190,] 60.56191 33.05879
[191,] 60.56055 33.13784
[192,] 60.71807 33.32354
[193,] 60.76689 33.36382
[194,] 60.85928 33.45625
[195,] 60.91699 33.50522
[196,] 60.90693 33.53896
[197,] 60.80645 33.55869
[198,] 60.65459 33.56040
[199,] 60.57383 33.58833
[200,] 60.51084 33.63892
[201,] 60.48594 33.71191
[202,] 60.52705 33.84199
[203,] 60.48574 34.09478
[204,] 60.57021 34.21963
[205,] 60.64268 34.30718
[206,] 60.88945 34.31943
[207,] 60.80391 34.41802
[208,] 60.76260 34.47524
[209,] 60.73613 34.49180
[210,] 60.72627 34.51826
[211,] 60.73945 34.54473
[212,] 60.80234 34.55464
[213,] 60.84531 34.58770
[214,] 60.91475 34.63398
[215,] 60.95117 34.65386
[216,] 60.95781 34.71006
[217,] 60.99082 34.74976
[218,] 61.04043 34.79937
[219,] 61.08008 34.85562
[220,] 61.07021 34.92173
[221,] 61.10664 35.00112
[222,] 61.12314 35.05073
[223,] 61.14961 35.09375
[224,] 61.12646 35.15654
[225,] 61.10664 35.20947
[226,] 61.10000 35.27231
[227,] 61.13965 35.28887
[228,] 61.18926 35.31201
[229,] 61.19922 35.36162
[230,] 61.22568 35.42446
[231,] 61.24551 35.47407
[232,] 61.27852 35.51377
[233,] 61.28184 35.55342
[234,] 61.26201 35.61958
[235,] 61.34473 35.62949
[236,] 61.37773 35.59312
[237,] 61.42178 35.54580
[238,] 61.54277 35.45786
[239,] 61.62100 35.43232
[240,] 61.71973 35.41943
[241,] 61.84102 35.43149
[242,] 61.93809 35.44790
[243,] 61.98389 35.44370
[244,] 62.08965 35.37969
[245,] 62.21309 35.28994
[246,] 62.25283 35.25024
[247,] 62.27119 35.18911
[248,] 62.30781 35.17080
[249,] 62.38662 35.23125
[250,] 62.46289 35.25137
[251,] 62.53311 35.23989
[252,] 62.61055 35.23315
[253,] 62.68809 35.25532
[254,] 62.72266 35.27134
[255,] 62.85801 35.34966
[256,] 62.98027 35.40918
[257,] 63.05664 35.44580
[258,] 63.08418 35.56807
[259,] 63.11934 35.63755
[260,] 63.16973 35.67812
[261,] 63.15078 35.72827
[262,] 63.12998 35.76675
[263,] 63.10859 35.81870
[264,] 63.12998 35.84619
[265,] 63.17891 35.85845
[266,] 63.30166 35.85840
[267,] 63.51699 35.91313
[268,] 63.69658 35.96782
[269,] 63.86250 36.01235
[270,] 63.93809 36.01973
[271,] 64.00967 36.01211
[272,] 64.04238 36.02510
[273,] 64.05137 36.06763
[274,] 64.09219 36.11270
[275,] 64.18438 36.14893
[276,] 64.35801 36.22607
[277,] 64.51104 36.34067
[278,] 64.56582 36.42759
[279,] 64.60254 36.55454
[280,] 64.67432 36.75020
[281,] 64.75313 36.96479
[282,] 64.78242 37.05928
[283,] 64.81631 37.13208
[284,] 64.95156 37.19355
[285,] 65.08965 37.23794
[286,] 65.30361 37.24678
[287,] 65.55498 37.25117
[288,] 65.60801 37.36841
[289,] 65.64121 37.46782
[290,] 65.68301 37.51914
[291,] 65.74385 37.56084
[292,] 65.76504 37.56914
[293,] 65.90068 37.50811
[294,] 66.10840 37.41475
[295,] 66.35029 37.36816
[296,] 66.47188 37.34473
[297,] 66.52227 37.34849
[298,] 66.82773 37.37129
[299,] 67.06885 37.33481
[300,] 67.19551 37.23521
[301,] 67.31973 37.20957
[302,] 67.44170 37.25801
[303,] 67.51729 37.26665
[304,] 67.54648 37.23564
[305,] 67.60742 37.22251
[306,] 67.70000 37.22725
[307,] 67.75293 37.19980
[308,] 67.75898 37.17222
[309,] 67.76602 37.14014
[310,] 67.83447 37.06421
[311,] 67.95801 36.97202
[312,] 68.06777 36.94980
[313,] 68.21211 37.02153
[314,] 68.26094 37.01309
[315,] 68.28477 37.03633
[316,] 68.29951 37.08843
[317,] 68.38691 37.13750
[318,] 68.54648 37.18345
[319,] 68.63701 37.22446
[320,] 68.66914 37.25840
[321,] 68.72324 37.26802
[322,] 68.78203 37.25801
[323,] 68.82373 37.27070
[324,] 68.83848 37.30283
[325,] 68.85537 37.31685
[326,] 68.88525 37.32808
[327,] 68.91182 37.33394
[328,] 68.96045 37.32505
[329,] 69.05000 37.26650
[330,] 69.18018 37.15830
[331,] 69.26484 37.10840
[332,] 69.30391 37.11694
[333,] 69.35381 37.15005
[334,] 69.41445 37.20776
[335,] 69.42969 37.29087
[336,] 69.39922 37.39932
[337,] 69.42012 37.48672
[338,] 69.49209 37.55308
[339,] 69.62578 37.59404
[340,] 69.82090 37.60957
[341,] 69.94063 37.60029
[342,] 69.98496 37.56616
[343,] 70.04473 37.54722
[344,] 70.11982 37.54351
[345,] 70.18867 37.58247
[346,] 70.25146 37.66416
[347,] 70.25498 37.76538
[348,] 70.19941 37.88604
[349,] 70.21465 37.92441
[350,] 70.23877 37.94121
[351,] 70.31328 37.98481
[352,] 70.41777 38.07544
[353,] 70.51855 38.19199
[354,] 70.61582 38.33442
[355,] 70.73594 38.42256
[356,] 70.87891 38.45640
[357,] 71.05215 38.41787
[358,] 71.25586 38.30698
[359,] 71.33271 38.17026
[360,] 71.28281 38.00791
[361,] 71.27852 37.91841
[362,] 71.31992 37.90186
[363,] 71.38965 37.90630
[364,] 71.48779 37.93188
[365,] 71.55195 37.93315
[366,] 71.58223 37.91011
[367,] 71.58037 37.86426
[368,] 71.54619 37.79565
[369,] 71.50508 37.60293
[370,] 71.47969 37.43604
[371,] 71.45479 37.27183
[372,] 71.43291 37.12754
[373,] 71.47188 37.01509
[374,] 71.53086 36.84512
[375,] 71.59746 36.73291
[376,] 71.66563 36.69692
[377,] 71.73379 36.68403
[378,] 71.80205 36.69429
[379,] 71.94199 36.76646
[380,] 72.15352 36.90054
[381,] 72.35879 36.98291
[382,] 72.65742 37.02905
[383,] 72.75703 37.17271
[384,] 72.89551 37.26753
[385,] 73.21113 37.40850
[386,] 73.38291 37.46226
[387,] 73.48135 37.47168
[388,] 73.60469 37.44604
[389,] 73.63262 37.43721
[390,] 73.65713 37.43047
[391,] 73.72061 37.41875
[392,] 73.73379 37.37578
[393,] 73.71729 37.32944
[394,] 73.64883 37.29121
[395,] 73.62754 37.26157
[396,] 73.65352 37.23936
[397,] 73.74961 37.23179
[398,] 73.94883 37.28315
[399,] 74.07773 37.31621
[400,] 74.16709 37.32944
[401,] 74.20352 37.37246
[402,] 74.25967 37.41543
[403,] 74.34902 37.41875
[404,] 74.44492 37.39561
[405,] 74.52422 37.38237
[406,] 74.65938 37.39448
[407,] 74.73057 37.35703
[408,] 74.83047 37.28594
[409,] 74.87539 37.24199
[410,] 74.89131 37.23164
Slot "plotOrder":
[1] 1
Slot "labpt":
[1] 66.00473 33.83523
Slot "ID":
[1] "1"
Slot "area":
[1] 62.55793
[[3]]
An object of class "Polygons"
Slot "Polygons":
[[1]]
An object of class "Polygon"
Slot "labpt":
[1] 17.56444 -12.33195
Slot "area":
[1] 103.0391
Slot "hole":
[1] FALSE
Slot "ringDir":
[1] 1
Slot "coords":
[,1] [,2]
[1,] 14.19082 -5.875977
[2,] 14.39863 -5.892676
[3,] 14.65791 -5.888867
[4,] 14.74941 -5.880078
[5,] 15.08936 -5.874512
[6,] 15.42500 -5.868848
[7,] 15.72695 -5.863867
[8,] 16.06016 -5.864941
[9,] 16.31523 -5.865625
[10,] 16.43145 -5.900195
[11,] 16.53711 -5.965820
[12,] 16.58516 -6.025293
[13,] 16.60801 -6.051562
[14,] 16.63955 -6.114551
[15,] 16.69727 -6.164258
[16,] 16.71777 -6.241406
[17,] 16.70098 -6.345996
[18,] 16.70938 -6.471680
[19,] 16.74297 -6.618457
[20,] 16.81309 -6.772559
[21,] 16.91943 -6.933984
[22,] 16.96582 -7.062109
[23,] 16.95205 -7.157031
[24,] 16.98477 -7.257422
[25,] 17.06377 -7.363086
[26,] 17.12158 -7.419043
[27,] 17.15508 -7.461328
[28,] 17.24502 -7.623340
[29,] 17.41133 -7.881934
[30,] 17.53604 -8.075879
[31,] 17.57959 -8.099023
[32,] 17.64336 -8.090723
[33,] 17.77881 -8.071387
[34,] 17.91309 -8.067676
[35,] 18.00879 -8.107617
[36,] 18.04717 -8.100781
[37,] 18.19150 -8.023828
[38,] 18.33486 -8.000293
[39,] 18.48467 -7.968555
[40,] 18.56270 -7.935938
[41,] 18.65342 -7.936035
[42,] 18.89834 -7.998145
[43,] 18.94443 -8.001465
[44,] 19.14268 -8.001465
[45,] 19.34082 -7.966602
[46,] 19.36992 -7.706543
[47,] 19.37168 -7.655078
[48,] 19.41934 -7.557324
[49,] 19.47988 -7.472168
[50,] 19.48740 -7.390723
[51,] 19.48379 -7.279492
[52,] 19.52764 -7.144434
[53,] 19.66035 -7.037109
[54,] 19.87520 -6.986328
[55,] 19.99746 -6.976465
[56,] 20.19004 -6.946289
[57,] 20.48223 -6.915820
[58,] 20.59004 -6.919922
[59,] 20.59873 -6.935156
[60,] 20.53691 -7.121777
[61,] 20.53584 -7.182812
[62,] 20.55840 -7.244434
[63,] 20.60781 -7.277734
[64,] 20.91094 -7.281445
[65,] 21.19033 -7.284961
[66,] 21.51084 -7.296680
[67,] 21.75107 -7.305469
[68,] 21.78164 -7.314648
[69,] 21.80605 -7.328613
[70,] 21.84160 -7.420996
[71,] 21.83359 -7.601660
[72,] 21.78008 -7.865430
[73,] 21.80088 -8.111914
[74,] 21.89590 -8.341113
[75,] 21.90537 -8.693359
[76,] 21.87188 -8.903516
[77,] 21.82949 -9.168457
[78,] 21.81318 -9.468750
[79,] 21.85664 -9.594238
[80,] 21.94863 -9.725586
[81,] 22.08916 -9.862793
[82,] 22.19775 -10.040625
[83,] 22.27451 -10.259082
[84,] 22.30244 -10.396680
[85,] 22.28164 -10.453320
[86,] 22.28320 -10.551562
[87,] 22.30703 -10.691309
[88,] 22.28047 -10.783984
[89,] 22.20352 -10.829492
[90,] 22.17793 -10.892285
[91,] 22.21670 -11.012695
[92,] 22.22617 -11.121973
[93,] 22.25664 -11.163672
[94,] 22.27881 -11.194141
[95,] 22.31494 -11.198633
[96,] 22.39297 -11.159473
[97,] 22.48613 -11.086719
[98,] 22.56104 -11.055859
[99,] 22.66650 -11.059766
[100,] 22.81475 -11.080273
[101,] 23.07627 -11.087891
[102,] 23.15674 -11.074805
[103,] 23.40020 -10.976465
[104,] 23.46396 -10.969336
[105,] 23.55996 -10.978613
[106,] 23.69639 -11.007617
[107,] 23.83389 -11.013672
[108,] 23.90117 -10.983203
[109,] 23.90732 -10.943457
[110,] 23.92871 -10.891504
[111,] 23.96650 -10.871777
[112,] 23.98828 -11.002832
[113,] 24.01006 -11.184766
[114,] 24.02559 -11.315625
[115,] 24.04141 -11.374121
[116,] 24.04668 -11.405371
[117,] 24.02930 -11.439160
[118,] 24.01465 -11.517676
[119,] 23.98682 -11.587207
[120,] 23.97100 -11.635840
[121,] 23.98389 -11.725000
[122,] 23.97344 -11.852930
[123,] 23.96230 -11.987891
[124,] 23.95889 -12.117773
[125,] 23.99648 -12.350684
[126,] 23.99131 -12.422168
[127,] 23.94473 -12.543750
[128,] 23.90938 -12.636133
[129,] 23.88652 -12.743262
[130,] 23.88242 -12.799023
[131,] 23.96807 -12.956934
[132,] 23.96299 -12.988477
[133,] 23.89746 -12.998242
[134,] 23.84316 -13.000977
[135,] 23.63584 -13.000977
[136,] 23.33867 -13.000977
[137,] 23.04150 -13.000977
[138,] 22.74434 -13.000977
[139,] 22.47100 -13.000977
[140,] 22.20957 -13.000977
[141,] 21.97891 -13.000977
[142,] 21.97900 -13.156836
[143,] 21.97910 -13.477734
[144,] 21.97910 -13.798730
[145,] 21.97930 -14.119629
[146,] 21.97939 -14.440527
[147,] 21.97949 -14.761426
[148,] 21.97959 -15.082324
[149,] 21.97969 -15.403223
[150,] 21.97979 -15.724121
[151,] 21.97979 -15.955566
[152,] 22.04023 -16.262793
[153,] 22.15068 -16.597168
[154,] 22.19395 -16.628125
[155,] 22.30508 -16.689551
[156,] 22.45947 -16.815137
[157,] 22.54600 -16.910254
[158,] 22.72197 -17.075293
[159,] 22.95586 -17.285742
[160,] 23.18164 -17.474414
[161,] 23.38066 -17.640625
[162,] 23.06826 -17.698828
[163,] 22.62402 -17.781641
[164,] 22.32422 -17.837500
[165,] 21.96084 -17.905176
[166,] 21.71846 -17.947754
[167,] 21.41689 -18.000684
[168,] 21.36875 -17.999512
[169,] 21.28789 -17.962988
[170,] 21.11348 -17.955762
[171,] 20.90830 -18.006055
[172,] 20.74551 -18.019727
[173,] 20.62510 -17.996680
[174,] 20.50762 -17.952539
[175,] 20.39297 -17.887402
[176,] 20.19434 -17.863672
[177,] 19.91182 -17.881348
[178,] 19.63936 -17.868652
[179,] 19.37715 -17.825488
[180,] 19.18945 -17.808496
[181,] 19.07646 -17.817676
[182,] 18.95527 -17.803516
[183,] 18.82598 -17.766309
[184,] 18.71807 -17.703223
[185,] 18.58818 -17.570020
[186,] 18.48662 -17.442773
[187,] 18.46035 -17.424609
[188,] 18.42822 -17.405176
[189,] 18.39639 -17.399414
[190,] 18.10879 -17.395996
[191,] 17.83535 -17.392773
[192,] 17.67881 -17.392578
[193,] 17.29629 -17.391992
[194,] 16.91367 -17.391406
[195,] 16.53105 -17.390820
[196,] 16.14844 -17.390234
[197,] 15.76582 -17.389648
[198,] 15.38320 -17.389160
[199,] 15.00059 -17.388574
[200,] 14.61797 -17.387988
[201,] 14.41475 -17.387695
[202,] 14.22588 -17.397754
[203,] 14.01748 -17.408887
[204,] 13.98740 -17.404199
[205,] 13.93799 -17.388770
[206,] 13.90420 -17.360742
[207,] 13.79199 -17.288379
[208,] 13.69434 -17.233496
[209,] 13.56172 -17.141211
[210,] 13.47598 -17.040039
[211,] 13.40371 -17.007812
[212,] 13.27568 -16.989551
[213,] 13.17949 -16.971680
[214,] 13.10117 -16.967676
[215,] 12.96318 -17.015430
[216,] 12.85928 -17.062598
[217,] 12.78516 -17.108203
[218,] 12.65654 -17.160547
[219,] 12.54814 -17.212695
[220,] 12.35928 -17.205859
[221,] 12.31846 -17.213379
[222,] 12.21338 -17.209961
[223,] 12.11436 -17.164551
[224,] 12.01396 -17.168555
[225,] 11.90254 -17.226562
[226,] 11.74307 -17.249219
[227,] 11.78008 -16.871289
[228,] 11.81895 -16.704102
[229,] 11.81992 -16.504297
[230,] 11.79697 -15.986426
[231,] 11.76943 -15.915332
[232,] 11.75088 -15.831934
[233,] 11.84971 -15.768359
[234,] 11.89990 -15.719824
[235,] 11.96787 -15.633984
[236,] 12.01611 -15.513672
[237,] 12.07324 -15.248242
[238,] 12.28047 -14.637500
[239,] 12.37891 -14.039063
[240,] 12.50371 -13.755469
[241,] 12.55049 -13.437793
[242,] 12.89766 -13.027734
[243,] 12.98320 -12.775684
[244,] 13.16270 -12.652148
[245,] 13.41699 -12.520410
[246,] 13.59795 -12.286133
[247,] 13.68555 -12.123828
[248,] 13.78535 -11.812793
[249,] 13.78428 -11.487988
[250,] 13.84746 -11.054395
[251,] 13.83359 -10.929688
[252,] 13.73896 -10.757129
[253,] 13.72139 -10.633594
[254,] 13.63350 -10.512305
[255,] 13.53945 -10.420703
[256,] 13.49541 -10.257129
[257,] 13.33223 -9.998926
[258,] 13.28750 -9.826758
[259,] 13.20938 -9.703223
[260,] 13.19688 -9.550684
[261,] 13.15566 -9.389648
[262,] 13.07598 -9.230371
[263,] 12.99854 -9.048047
[264,] 12.99854 -8.991016
[265,] 13.04678 -8.922266
[266,] 13.09277 -8.899707
[267,] 13.07725 -8.934277
[268,] 13.04658 -8.975195
[269,] 13.05381 -9.006836
[270,] 13.35898 -8.687207
[271,] 13.37832 -8.624707
[272,] 13.36807 -8.554785
[273,] 13.36641 -8.469238
[274,] 13.37852 -8.369727
[275,] 13.09082 -7.780176
[276,] 12.86230 -7.231836
[277,] 12.82344 -6.954785
[278,] 12.52129 -6.590332
[279,] 12.40215 -6.353418
[280,] 12.33428 -6.187305
[281,] 12.28330 -6.124316
[282,] 12.30254 -6.092578
[283,] 12.38037 -6.084277
[284,] 12.55352 -6.045898
[285,] 12.79063 -6.003906
[286,] 13.00977 -5.907617
[287,] 13.06816 -5.864844
[288,] 13.18438 -5.856250
[289,] 13.30264 -5.881836
[290,] 13.34648 -5.863379
[291,] 13.37148 -5.861816
[292,] 13.64902 -5.861719
[293,] 13.76455 -5.855176
[294,] 13.97852 -5.857227
[295,] 14.11377 -5.865137
[296,] 14.19082 -5.875977
[[2]]
An object of class "Polygon"
Slot "labpt":
[1] 12.448313 -5.039424
Slot "area":
[1] 0.5481372
Slot "hole":
[1] FALSE
Slot "ringDir":
[1] 1
Slot "coords":
[,1] [,2]
[1,] 12.25527 -5.746484
[2,] 12.21367 -5.758691
[3,] 12.19902 -5.731934
[4,] 12.15547 -5.632715
[5,] 12.18008 -5.538672
[6,] 12.20654 -5.468262
[7,] 12.17715 -5.324805
[8,] 12.11055 -5.197168
[9,] 12.03994 -5.035156
[10,] 12.01836 -5.004297
[11,] 12.07754 -4.952148
[12,] 12.16709 -4.837695
[13,] 12.20430 -4.778613
[14,] 12.30791 -4.765527
[15,] 12.34668 -4.724121
[16,] 12.37402 -4.657715
[17,] 12.38457 -4.619141
[18,] 12.50146 -4.587500
[19,] 12.64170 -4.531152
[20,] 12.71943 -4.469727
[21,] 12.79824 -4.430566
[22,] 12.84814 -4.428906
[23,] 12.88105 -4.445117
[24,] 12.97139 -4.551758
[25,] 13.04805 -4.619238
[26,] 13.07275 -4.634766
[27,] 13.05732 -4.651074
[28,] 12.94746 -4.695312
[29,] 12.82969 -4.736621
[30,] 12.67480 -4.905371
[31,] 12.59619 -4.978418
[32,] 12.57354 -4.996582
[33,] 12.50273 -5.036914
[34,] 12.45146 -5.071484
[35,]
12.45322 -5.090625
[36,] 12.48740 -5.112695
[37,] 12.52236 -5.148926
[38,] 12.51895 -5.424609
[39,] 12.50371 -5.695801
[40,] 12.48457 -5.718750
[41,] 12.38604 -5.727734
[42,] 12.25527 -5.746484
Slot "plotOrder":
[1] 1 2
Slot "labpt":
[1] 17.56444 -12.33195
Slot "ID":
[1] "2"
Slot "area":
[1] 103.5873
[[4]]
An object of class "Polygons"
Slot "Polygons":
[[1]]
An object of class "Polygon"
Slot "labpt":
[1] -63.06499 18.22396
Slot "area":
[1] 0.007091551
Slot "hole":
[1] FALSE
Slot "ringDir":
[1] 1
Slot "coords":
[,1] [,2]
[1,] -63.00122 18.22178
[2,] -63.16001 18.17139
[3,] -63.15332 18.20029
[4,] -63.02603 18.26973
[5,] -62.97959 18.26479
[6,] -63.00122 18.22178
Slot "plotOrder":
[1] 1
Slot "labpt":
[1] -63.06499 18.22396
Slot "ID":
[1] "3"
Slot "area":
[1] 0.007091551
[[5]]
An object of class "Polygons"
Slot "Polygons":
[[1]]
An object of class "Polygon"
Slot "labpt":
[1] 20.04983 41.14245
Slot "area":
[1] 3.043388
Slot "hole":
[1] FALSE
Slot "ringDir":
[1] 1
Slot "coords":
[,1] [,2]
[1,] 20.06396 42.54727
[2,] 20.10352 42.52466
[3,] 20.18574 42.42588
[4,] 20.24053 42.33896
[5,] 20.34824 42.30879
[6,] 20.40830 42.27495
[7,] 20.48545 42.22339
[8,] 20.52285 42.17148
[9,] 20.57539 42.01309
[10,] 20.58145 41.91743
[11,] 20.56621 41.87368
[12,] 20.55313 41.86235
[13,] 20.50518 41.70649
[14,] 20.51660 41.62705
[15,] 20.51621 41.57476
[16,] 20.47559 41.55410
[17,] 20.44863 41.52129
[18,] 20.49238 41.39141
[19,] 20.48701 41.33608
[20,] 20.48896 41.27261
[21,] 20.56787 41.12783
[22,] 20.61445 41.08306
[23,] 20.65605 41.06167
[24,] 20.70928 40.92837
[25,] 20.74082 40.90527
[26,] 20.87021 40.91792
[27,] 20.93350 40.90312
[28,] 20.95859 40.87153
[29,] 20.96426 40.84990
[30,] 20.95576 40.77529
[31,] 20.98789 40.71777
[32,] 21.03105 40.65864
[33,] 21.03086 40.62246
[34,] 21.00195 40.56338
[35,] 20.95020 40.49438
[36,] 20.88164 40.46792
[37,] 20.80605 40.44546
[38,] 20.77002 40.39189
[39,] 20.75166 40.33491
[40,] 20.71787 40.29268
[41,] 20.69697 40.24639
[42,] 20.66494 40.15176
[43,] 20.65742 40.11738
[44,] 20.60625 40.08267
[45,] 20.52705 40.06851
[46,] 20.45605 40.06558
[47,] 20.40801 40.04946
[48,] 20.38369 40.01719
[49,] 20.33848 39.99106
[50,] 20.31113 39.97944
[51,] 20.31133 39.95078
[52,] 20.34424 39.89062
[53,] 20.38164 39.84180
[54,] 20.38242 39.80264
[55,] 20.36406 39.79175
[56,] 20.30615 39.79668
[57,] 20.29385 39.78223
[58,] 20.28760 39.73857
[59,] 20.27207 39.70117
[60,] 20.24824 39.67837
[61,] 20.20684 39.65352
[62,] 20.13105 39.66162
[63,] 20.05977 39.69912
[64,] 20.02256 39.71069
[65,] 20.00127 39.70942
[66,] 19.99561 39.80103
[67,] 19.96484 39.87227
[68,] 19.85186 40.04355
[69,] 19.48457 40.20996
[70,] 19.39814 40.28486
[71,] 19.36016 40.34771
[72,] 19.32227 40.40708
[73,] 19.35859 40.40874
[74,] 19.39453 40.39370
[75,] 19.44053 40.37568
[76,] 19.45918 40.40537
[77,] 19.43926 40.47026
[78,] 19.34463 40.62207
[79,] 19.33750 40.66382
[80,] 19.38389 40.79072
[81,] 19.46123 40.93330
[82,] 19.45605 41.10605
[83,] 19.48008 41.23638
[84,] 19.45342 41.32100
[85,] 19.44063 41.42476
[86,] 19.49736 41.56270
[87,] 19.54580 41.59683
[88,] 19.57568 41.64043
[89,] 19.57754 41.78750
[90,] 19.46826 41.85615
[91,] 19.34238 41.86909
[92,] 19.34551 41.91885
[93,] 19.36113 41.99775
[94,] 19.35215 42.02402
[95,] 19.36143 42.06909
[96,] 19.33086 42.12930
[97,] 19.28066 42.17256
[98,] 19.32900 42.24927
[99,] 19.39961 42.34189
[100,] 19.46514 42.41538
[101,] 19.54453 42.49194
[102,] 19.59746 42.56543
[103,] 19.65449 42.62856
[104,] 19.70342 42.64795
[105,] 19.72783 42.63452
[106,] 19.74072 42.60693
[107,] 19.73779 42.52515
[108,] 19.75449 42.49692
[109,] 19.78828 42.47617
[110,] 19.85977 42.48633
[111,] 19.93906 42.50669
[112,] 20.04570 42.54990
[113,] 20.06396 42.54727
Slot "plotOrder":
[1] 1
Slot "labpt":
[1] 20.04983 41.14245
Slot "ID":
[1] "4"
Slot "area":
[1] 3.043388
[[6]]
An object of class "Polygons"
Slot "Polygons":
[[1]]
An object of class "Polygon"
Slot "labpt":
[1] 20.51543 60.04434
Slot "area":
[1] 0.008765941
Slot "hole":
[1] FALSE
Slot "ringDir":
[1] 1
Slot "coords":
[,1] [,2]
[1,] 20.61133 60.04067
[2,] 20.60342 60.01694
[3,] 20.52178 60.01167
[4,] 20.48750 60.03276
[5,] 20.41123 60.03013
[6,] 20.39795 60.04067
[7,] 20.42959 60.06172
[8,] 20.49014 60.07490
[9,] 20.56914 60.06963
[10,] 20.61133 60.04067
[[2]]
An object of class "Polygon"
Slot "labpt":
[1] 19.58766 60.19482
Slot "area":
[1] 0.01083552
Slot "hole":
[1] FALSE
Slot "ringDir":
[1] 1
Slot "coords":
[,1] [,2]
[1,] 19.66230 60.18716
[2,] 19.66748 60.16475
[3,] 19.62920 60.17036
[4,] 19.59980 60.16270
[5,] 19.57988 60.13506
[6,] 19.53652 60.14497
[7,] 19.51904 60.18457
[8,] 19.55137 60.24385
[9,] 19.62881 60.24609
[10,] 19.66230 60.18716
[[3]]
An object of class "Polygon"
Slot "labpt":
[1] 19.94401 60.23133
Slot "area":
[1] 0.1041173
Slot "hole":
[1] FALSE
Slot "ringDir":
[1] 1
Slot "coords":
[,1] [,2]
[1,] 19.98955 60.35117
[2,] 20.02021 60.35088
[3,] 20.03389 60.35933
[4,] 20.08740 60.35342
[5,] 20.16787 60.31470
[6,] 20.18408 60.29375
[7,] 20.23955 60.28301
[8,] 20.25889 60.26128
[9,] 20.19473 60.19355
[10,] 20.15508 60.19229
[11,] 20.12549 60.20088
[12,] 20.07324 60.19346
[13,] 20.04258 60.18066
[14,] 20.03232 60.15249
[15,] 20.03398 60.09355
[16,] 19.79980 60.08174
[17,] 19.74600 60.09897
[18,] 19.67227 60.23301
[19,] 19.68691 60.26763
[20,] 19.73652 60.28237
[21,] 19.77900 60.28555
[22,] 19.78525 60.21338
[23,] 19.84766 60.22056
[24,] 19.86719 60.26812
[25,] 19.87158 60.30161
[26,] 19.85469 60.31851
[27,] 19.81230 60.33159
[28,] 19.78779 60.35405
[29,] 19.82305 60.39019
[30,] 19.88828 60.40581
[31,] 19.94453 60.35752
[32,] 19.98955 60.35117
Slot "plotOrder":
[1] 3 2 1
Slot "labpt":
[1] 19.94401 60.23133
Slot "ID":
[1] "5"
Slot "area":
[1] 0.1237188
Slot "plotOrder":
[1] 3 2 5 6 1 4
Slot "bbox":
min max
x -70.06611 74.89131
y -18.01973 60.40581
Slot "proj4string":
CRS arguments:
+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
gdp_data <- read.csv("WorldGDP.csv")
head(gdp_data)
#match country top gdp data
rates <- gdp_data$GDP[match(world_map$admin, gdp_data$Name)]
#create the map
#set the colours
qpal <- colorQuantile("Blues",
rates,
9)
#blank canvas
leaflet(world_map) %>% #what data to use
#add tile
addTiles() %>%
#draw polygons on top of base map/ tile
addPolygons(
stroke = FALSE,
smoothFactor = 0.2,
fillOpacity = 1,
color = ~qpal(rates)
)
NA
library(shiny)
ui <- fluidPage(
#create map canvas on page
leafletOutput("mymap"),
#creat a button and bind it to the recalc event
actionButton("recalc", "New points")
)
server <- function(input, output, session) {
#event handle, thios is in case for click event
points<- eventReactive(input$recalc, {
#calculate normal distribution random points around melbourne
cbind(rnorm(40) * 3 + 145.0431, rnorm(40) -37.8773)
}, ignoreNULL = FALSE)
output$mymap <- renderLeaflet({ #create leaflet map
#blank canvas
leaflet() %>%
#add tile
addTiles() %>%
#use radomly generated points as markers on the map
addMarkers(data = points())
})
}
shinyApp(ui, server)
Listening on http://127.0.0.1:5271
NA